<template>
	<!-- 申请单出库, 入库单出库 -->
	<view class="">
		<view class="card-wrapper">
			<view class="radius shadow shadow-lg bg-white padding-sm light bg-blue">
				<view class="flex flex-wrap">
					<view class="basis-xs">
						单据编号:
					</view>
					<view class="basis-xl text-black">
						{{ mainOrder.BILLNO }}
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						集团:
					</view>
					<view class="basis-xl text-black">
						{{ mainOrder.GROUPNAME || '' }}
					</view>
				</view>
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						组织:
					</view>
					<view class="basis-xl text-black">
						{{ mainOrder.ORGNAME || '' }}
					</view>
				</view>
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						部门:
					</view>
					<view class="basis-xl text-black">
						{{ mainOrder.DEPTNAME || '' }}
					</view>
				</view>

				<!-- <view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						供应商:
					</view>
					<view class="basis-xl text-black">
						{{ mainOrder.SUPPLYNAME || '' }}
					</view>
				</view> -->

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs ">
						出库类型<span class="text-red">*</span>
					</view>
					<view class="basis-xl solid-bottom  text-black">
						<picker @change="bindPickerChange($event,'1')" :value="outTypeIndex" :range="outType"
							:range-key="'ItemName'" class="picker-wrap">
							<view> {{ $utils.getExNumName(outType,mainOrder.OUTTYPE) || '请选择' }} </view>
							<text class="dicon diconxiangxiazhankai position-a down-arrow"></text>
						</picker>
					</view>
				</view>

				<!--库类型选择生产领用， 所属产品必填  -->
				<view class="flex flex-wrap margin-top" v-if="mainOrder.OUTTYPE ==1 || mainOrder.OUTTYPE == 2  ">
					<view class="basis-xs">
						所属产品<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexPRO('pp')">
						<input class="wc-input " disabled type="text" :value="mainOrder.PRODUCTNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs">
						在建工程<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(1,'在建工程')">
						<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.ZJGCNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top"
					v-if="mainOrder.OUTTYPE ==1 || mainOrder.OUTTYPE == 2 || mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs">
						研发工程<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(2,'研发工程')">
						<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.YFGCNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<!-- <view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs ">
						是否资产<span class="text-red">*</span>
					</view>
					<view class="basis-xl solid-bottom  text-black radio-wrap">
						<radio-group @change="radioChange">
							<label class="radio">
								<radio value="1" :checked="mainOrder.ISMEANS==1" />是
							</label>
							<label class="radio">
								<radio value="0" :checked="mainOrder.ISMEANS==0" />否
							</label>
						</radio-group>
					</view>
				</view>

				<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs">
						资产<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(6,'资产')">
						<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.MEANSNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs">
						维修日期<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @click="dateEvent('NEXTPAIRDATE','M')">
						{{ mainOrder.NEXTPAIRDATE }}
					</view>
				</view> -->

				<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs">
						单车核算<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(3,'单车核算')">
						<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.DCHSNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
					<view class="basis-xs">
						核算分类<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(4,'核算分类')">
						<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.HSFLNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>


				<view class="flex flex-wrap margin-top"
					v-if="outType,mainOrder.OUTTYPE !=3 ||  outType,mainOrder.OUTTYPE !=4">
					<view class="basis-xs">
						业务类型<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(5,'业务类型')">
						<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.YWLXNAME"
							placeholder="请选择" />
						<view class="basis-xs text-right position-a down-arrow-btn ">
							<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						申请人:
					</view>
					<view class="basis-xl text-black">
						{{ mainOrder.APPLYER || '' }}
					</view>
				</view>

				<view class="flex flex-wrap margin-top ">
					<view class="basis-xs">
						备注:
					</view>
					<view class="basis-xl text-black ">
						{{ mainOrder.VMEMO }}
					</view>
				</view>
			</view>
			<!-- 物资子表 -->

			<view class="radius shadow shadow-lg bg-white padding-sm margin-top sub-table"
				v-for="(item,index) in planList" :key="index">

				<view class="flex flex-wrap ">
					<view class="basis-xs">
						物资状态
					</view>

					<view class="basis-xl text-black position-r ">
						<input class="wc-input" :class="item.flagText=='已扫码确认'?'text-green':'text-red'" disabled
							style="width: 60%;" type="text" :value="item.flagText" />
						<view class="basis-xs text-right position-a scan-btn " @tap="openScan('STORE',index)">
							<text class="cuIcon-scan text-xxl text-bold"></text>
						</view>
					</view>
				</view>


				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						物资单号
					</view>
					<view class="basis-xl text-black">
						{{ item.PK_MATERIAL }}
					</view>
				</view>
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						物资名称
					</view>
					<view class="basis-xl text-black">
						{{ item.MATERIALNAME || '' }}
					</view>
				</view>
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						规格型号
					</view>
					<view class="basis-xl text-black">
						{{ item.MATSPEC || '' }}
					</view>
				</view>

				<view class="" v-if=" mainOrder.OUTTYPE ==6 ">
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs">
							材质
						</view>
						<view class="basis-xl text-black">
							{{ item.MATQULITY }}
						</view>
					</view>
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs">
							产地
						</view>
						<view class="basis-xl text-black">
							{{ item.PRODUCTAREA || '' }}
						</view>
					</view>
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs">
							货主
						</view>
						<view class="basis-xl text-black">
							{{ item.SHIPER || '' }}
						</view>
					</view>
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs">
							重量
						</view>
						<view class="basis-xl text-black">
							{{ item.WEIGHTNUM || '' }} {{ item.WEIGHTUNIT || ''  }}
						</view>
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						推荐货位
					</view>
					<view class="basis-xl text-black">
						{{ item.STATIONNAME_TJ || '' }}
					</view>
				</view>

				<view class="flex flex-wrap margin-top line-height-30 ">
					<view class="basis-xs ">
						申请数量
					</view>
					<view class="basis-xl  text-black">
						{{ item.WNUM || '' }} /{{ item.UNIT }}
					</view>
				</view>

				<view class="flex flex-wrap margin-top line-height-30 ">
					<view class="basis-xs ">
						出库数量
					</view>
					<view class="basis-xl solid-bottom  sub-table-input">
						<input class="wc-input" v-model="item.NNUM" type="text" placeholder="请输入" />
					</view>
				</view>

				<!-- 子表维护是否资产 -->
				<view class="" v-if="mainOrder.OUTTYPE ==5">
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs ">
							是否资产<span class="text-red">*</span>
						</view>
						<view class="basis-xl solid-bottom  text-black radio-wrap">
							<radio-group @change="radioChange($event, index)">
								<label class="radio">
									<radio value="1" :checked="item.ISMEANS==1" />是
								</label>
								<label class="radio">
									<radio value="0" :checked="item.ISMEANS==0" />否
								</label>
							</radio-group>
						</view>
					</view>
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs">
							资产<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(6,'资产' , index)">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="item.MEANSNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs">
							维修日期<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @click="dateEvent('NEXTPAIRDATE', index )">
							{{ item.NEXTPAIRDATE }}
						</view>
					</view>	
				</view>


				<!-- <view class="flex flex-wrap margin-top ">
					<view class="basis-xs ">
						仓库<span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black position-r solid-bottom" :class="isActiveStore? 'solid-bottom-blue' :'' ">
						<input class="wc-input" disabled style="width: 60%;" name="STORENAME" type="text" placeholder="请扫描物资二维码" :value="item.STORENAME" />
					</view>
				</view> -->

				<view class="flex flex-wrap margin-top ">
					<view class="basis-xs">
						货位 <span class="text-red">*</span>
					</view>
					<view class="basis-xl text-black position-r solid-bottom"
						:class="isActiveStore? 'solid-bottom-blue' :'' ">
						<input class="wc-input" disabled style="width: 60%;" name="STATIONNAME" type="text"
							placeholder="请扫描物资二维码" :value="item.STATIONNAME" />
						<!-- <view class="basis-xs text-right position-a scan-btn " @tap="openScan('STATION',index)">
							<text class="cuIcon-scan text-xxl text-bold"></text>
						</view> -->
					</view>
				</view>

				<view class="flex flex-wrap margin-top line-height-30 ">
					<view class="basis-xs ">
						备注<span class="text-red">*</span>
					</view>
					<view class="basis-xl solid-bottom  sub-table-input">
						<input class="wc-input" v-model="item.VMEMO" type="text" placeholder="使用非推荐仓库和货位时必填备注说明" />
					</view>
				</view>
				
				
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						设备信息
					</view>
					<view class="basis-xl text-black position-r solid-bottom" :class="isActiveStore? 'solid-bottom-blue' :'' ">
						<input class="wc-input" style="width: 60%;" name="EQUIPNAME" type="text" :value="item.EQUIPNAME" placeholder="请选择"
						 @tap="activeIndexM(index,'EQBOM',true)" disabled />
						<view class="basis-xs text-right position-a scan-btn" @tap="handelScan(index)">
							<text class="cuIcon-scan text-xxl text-bold"></text>
						</view>
					</view>
				</view>
				

				<view class="flex flex-wrap margin-top ">
					<view class="basis-xs">
						生产日期
					</view>
					<view class="basis-xl text-black solid-bottom" @click="dateEvent('FACTORYDATE',index)">
						{{ item.FACTORYDATE }}
					</view>
				</view>

				<view class="flex flex-wrap margin-top ">
					<view class="basis-xs">
						保质期
					</view>
					<view class="basis-xl text-black solid-bottom">
						<input class="wc-input" v-model="item.EXPDATE" type="text" value="item.EXPDATE"
							placeholder="请输入到货量" />
					</view>
				</view>

				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						入库日期
					</view>
					<view class="basis-xl text-black" @click="dateEvent('INSTOCKDATE',index)">
						{{ item.INSTOCKDATE }}
					</view>
				</view>
				<!-- <view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						备注
					</view>
					<view class="basis-xl text-black" @click="dateEvent('INSTOCKDATE',index)">
						<input class="wc-input" v-model="item.VMEMO" placeholder="请输入备注" />
					</view>
				</view> -->


				<!-- <view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						图片上传
					</view>
					<view class="basis-xl text-black solid-bottom">
						{{ item.INPHOTO }} 
					</view>
				</view> -->
			</view>


			<view class="">
				<button class="cu-btn block bg-blue margin-tb-sm lg" @click="submit">
					<!-- <text class="cuIcon-loading2 cuIconfont-spin"></text> -->
					提交
				</button>
			</view>
		</view>

		<w-picker mode="dateTime" startYear="2000" endYear="2050" step="1" :defaultVal="[1,1,1,1,2,5]" :current="true"
			@confirm="onConfirm" ref="dateTime" themeColor="#f00"></w-picker>

	</view>

</template>
<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import wPicker from "@/components/w-picker/w-picker.vue";
	import api from '@/common/api.js';
	import utils from '@/common/util.js';
	let query = {
		"category": "ST_INAPPLY",
		"page": 1,
		"rows": "50",
		"sidx": "",
		"sord": "",
		"queryJson": {},
		"userId": "",
		"account": "admin"
	}
	let _self, dateTimekey, activeIndex, VMEMO, BILLFROM, ajaxUrl, activeType;
	export default {
		computed: mapState(['userInfo', 'taxRate', 'outType']),
		data() {
			return {
				bstype: '',
				outTypeIndex: 0,
				mainOrder: {
					OUTTYPE: '1',
					OUTTYPENAME: '生产出库',
					PK_PRODUCT: '',
					PRODUCTNAME: '',
					PK_ZJGC: '',
					ZJGCNAME: '',
					PK_YFGC: '',
					YFGCNAME: '',
					PK_DCHS: '',
					DCHSNAME: '',
					PK_HSFL: '',
					HSFLNAME: '',
					PK_YWLX: '',
					YWLXNAME: '',
					ISMEANS: 0, // 是否资产
					PK_MEANS: '', // 资产编号
					MEANSNAME: '', // 资产名称
					NEXTPAIRDATE: '', // 资产维修日期
				},
				planList: [],
				isActiveNote: false,
				isActiveStore: false,
				mid: '',
				today: utils.getToDay(),
				dateTimekey: '',
				VMEMO: '',
				activeIndex: '',
				label01: '单号', // 主表的第一个label
				flagText: '未扫码确认请扫码确认',
				activeLineIndex: 0 ,
			}
		},
		components: {
			wPicker
		},
		onLoad(p) {
			_self = this
			this.bstype = p.t
			query.userId = _self.userInfo.UserId
			query.account = _self.userInfo.Account
			query.category = p.dbt;
			// console.log(p.dbt);
			if (p.dbt == 'ST_INAPPLY' || p.dbt == 'ST_OUTAPPLY') {
				BILLFROM = 1
			} else if (p.dbt == 'PP_SUPLIST') {
				BILLFROM = 2
			} else if (p.dbt == 'PP_PURORDERS') {
				BILLFROM = 3
				query.category = 'PP_PURORDERS';
			} else if (p.dbt == 'ST_PURINSTORE') {
				query.category = 'ST_PURINSTORE';
			}
			let abc = JSON.parse(decodeURIComponent(p.item));
			// abc.PK_STORE = '' ;
			// abc.STORENAME = '' ;
			_self.mainOrder = {
				..._self.mainOrder,
				...abc,
			};
			_self.mainOrder.OUTTYPE = _self.mainOrder.OUTTYPE || '3'
			_self.mainOrder.OUTTYPENAME = _self.mainOrder.OUTTYPE || '销售出库'
			ajaxUrl = p.dbt == 'ST_OUTAPPLY' || p.dbt == 'ST_PURINSTORE' ? api.apiPublic.SaveOutStore : api.apiPublic
				.saveInStore;
			// console.log(777, _self.mainOrder);
			let queryJsonID = 'PK_' + query.category.split('_')[1];
			query.queryJson[queryJsonID] = p.id
			_self.mid = queryJsonID + '_DTL';
			_self.getDetail();
			this.setOnceEvent()
		},

		onShow() {
			uni.$on('getSelectItem', function(data) {
				// console.log(data);
				// console.log(activeType);
				switch (activeType) {
					case 'MSTORE': // 主表仓库
						_self.mainOrder.PK_STORE = data.BILLNO
						_self.mainOrder.STORENAME = data.VNAME
						break;
					case 'GROUP':
						_self.mainOrder.GROUPNAME = data.FullName
						_self.mainOrder.PK_GROUP = data.OrganizeId
						break;
					case 'BA_ORGANIZE':
						_self.mainOrder.ORGNAME = data.FullName
						_self.mainOrder.PK_ORG = data.OrganizeId
						break;
					case 'BA_DEPARTMENT':
						_self.mainOrder.DEPTNAME = data.FullName
						_self.mainOrder.PK_DEPT = data.OrganizeId
						break;
					case 'BA_USER':
						_self.mainOrder.APPLYER = data.RealName
						_self.mainOrder.PK_APPLYER = data.UserId
						break;
					case 'BD_STORE': // 仓库子
						_self.planList[activeIndex].PK_STORE = data.BILLNO
						_self.planList[activeIndex].STORENAME = data.VNAME
						break;
					case 'BD_RACK': // 货位子
						_self.planList[activeIndex].STATIONNAME = data.VNAME
						_self.planList[activeIndex].PK_STATION = data.BILLNO
						break;
					case "EQBOM": // 设备
						_self.planList[_self.activeLineIndex].EQUIPNAME = data.EQBOMNAME;
						_self.planList[_self.activeLineIndex].PK_EQUIP = data.PK_EM_EQBOM;
						break;
					default:
						break;
				}
			})
		},

		onUnload() {
			uni.$off('getSelectItem')
			uni.$off('getSelectItemPro')
			uni.$off('getSelectItemGS')
		},

		methods: {

			setOnceEvent() {
				uni.$on('getSelectItemPro', res => {
					this.mainOrder.PK_PRODUCT = res.VCODE
					this.mainOrder.PRODUCTNAME = res.VNAME
				})
				uni.$on('getSelectItemGS', res => {
					switch (res.TYPE) {
						case '1':
							this.mainOrder.PK_ZJGC = res.BILLNO
							this.mainOrder.ZJGCNAME = res.VNAME
							break;
						case '2':
							this.mainOrder.PK_YFGC = res.BILLNO
							this.mainOrder.YFGCNAME = res.VNAME
							break;
						case '3':
							this.mainOrder.PK_DCHS = res.BILLNO
							this.mainOrder.DCHSNAME = res.VNAME
							break;
						case '4':
							this.mainOrder.PK_HSFL = res.BILLNO
							this.mainOrder.HSFLNAME = res.VNAME
							break;
						case '5':
							this.mainOrder.PK_YWLX = res.BILLNO
							this.mainOrder.YWLXNAME = res.VNAME
							break;
						case '6':
							_self.planList[activeIndex].PK_MEANS = res.ZCBH
							_self.planList[activeIndex].MEANSNAME = res.ZCMC
							break;
					}
				})
			},

			activeIndexGS(i, Title , acindex) {
				activeIndex = acindex
				let SSType = i;
				uni.navigateTo({
					url: '/pages/public/search-gs?t=' + i + '&title=' + Title + '&Btype=' + this.outType[this
						.outTypeIndex].ItemValue
				})
			},
			activeIndexPRO(i, t, activeSub) {
				let SSType = i;
				uni.navigateTo({
					url: '/pages/public/search-pro?t=' + i
				})
			},
			
			activeIndexM(i, t) {
				_self.activeLineIndex = i;
				activeType = t;
				console.log('activeIndexM', i, t);
				let queryParames = "", pk_my_org = "";
				
				queryParames =  { PK_MATERIAL : this.planList[i].PK_MATERIAL }
				queryParames =	JSON.stringify(queryParames)
				
				
				uni.navigateTo({
					url: "/pages/public/search?t=" +
						t +
						"&organizeId=" +
						pk_my_org +
						"&queryjson=" +
						queryParames
				});
			},

			seachEvent(t, isMainTB, i, store) {
				// console.log(t,isMainTB,i,store);
				activeType = isMainTB == 1 ? 'MSTORE' : t;
				activeIndex = i // 激活的子表下标
				let queryParames = '';
				if (t == 'BD_RACK' && !this.mainOrder.PK_STORE) {
					return utils.tips('请先选择仓库');
				} else if (t == 'BD_RACK') {
					queryParames = JSON.stringify({
						PK_STORE: this.mainOrder.PK_STORE
					});
				}
				uni.navigateTo({
					url: '/pages/public/search?t=' + t + '&queryjson=' + queryParames
				})
			},
			onConfirm(val) {
				if (activeIndex == 'M') {
					_self.mainOrder.NEXTPAIRDATE = val.result
				} else {
					this.planList[activeIndex][dateTimekey] = val.result;
				}
			},

			bindPickerChange: function(e, i) {
				let val = e.target.value;
				_self.outTypeIndex = val
				_self.mainOrder.OUTTYPE = _self.outType[val].ItemValue
				_self.mainOrder.OUTTYPENAME = _self.outType[val].ItemName

				_self.mainOrder.PK_PRODUCT = ''
				_self.mainOrder.PRODUCTNAME = ''
				_self.mainOrder.PK_ZJGC = ''
				_self.mainOrder.ZJGCNAME = ''
				_self.mainOrder.PK_YFGC = ''
				_self.mainOrder.YFGCNAME = ''
				_self.mainOrder.PK_DCHS = ''
				_self.mainOrder.DCHSNAME = ''
				_self.mainOrder.PK_HSFL = ''
				_self.mainOrder.HSFLNAME = ''
				_self.mainOrder.PK_YWLX = ''
				_self.mainOrder.YWLXNAME = ''

			},
			radioChange(v,i) {
				let val = v.detail.value
				_self.planList[i].ISMEANS = val
			},
			dateEvent(id, index) {
				dateTimekey = id;
				activeIndex = index;
				this.$refs.dateTime.show();
			},
			openScan(id, index) {
				let URL = api.apiPublic.ScanCode;
				this.$utils.Scan(URL, data => {
					// console.log(data);
					if (data.PK_MATERIAL != _self.planList[index].PK_MATERIAL) {
						return utils.tips('扫描的物资单号和申请单号不匹配！');
					}

					if (_self.planList[index].STATIONNAME_TJ != data.STATIONNAME) {
						_self.planList[index].flagText = '非推荐物资'
					} else {
						_self.planList[index].flagText = '已扫码确认'
					}

					_self.planList[index].ISSURE = true
					_self.planList[index].PK_STORE = data.PK_STORE
					_self.planList[index].STORENAME = data.STORENAME
					_self.planList[index].STATIONNAME = data.STATIONNAME
					_self.planList[index].PK_STATION = data.PK_STATION
					_self.planList[index].BARCODE = data.BARCODE
					_self.planList[index].WNUM = data.NNUM || 0
				});

			},

			getDetail() {
				let URL = api.apiPublic.getMaterList;
				// console.log(query , URL); // GetDateAfter
				this.axios({
					url: URL,
					data: query,
				}).then(res => {
					// console.log(res);
					let {
						Result
					} = res;
					let array = Result.rows.map((item) => {
						item.FACTORYDATE = '';
						item.EXPDATE = '180';
						item.INSTOCKDATE = utils.getToDay();
						item.STORENAME_TJ = item.STORENAME;
						item.STATIONNAME_TJ = item.COMSTATNAME;
						// item.PK_STORE = '';
						item.STATIONNAME = item.COMSTATNAME;
						item.PK_STATION = item.PK_COMSTAT;
						item.INPHOTO = '';
						item.NNUM = item.WNUM;
						item.ISSURE = false
						item.flagText = '未扫码确认请扫码确认'
						
						item.MEANSNAME =  item.MEANSNAME || ''
						item.PK_MEANS = item.PK_MEANS || ''
						item.ISMEANS = item.ISMEANS || ''
						item.NEXTPAIRDATE = item.NEXTPAIRDATE || ''
						
						item.EQUIPNAME = item.EQUIPNAME || ''
						item.PK_EQUIP = item.PK_EQUIP || ''
						
						return item;
					})
					_self.planList = array
				})
			},
			
			handelScan(i){
				this.$utils.openScanUtils( i,i, (res)=>{
					if(res.includes('TYPE:8')){
						let arr = res.split('|')
						_self.planList[i].EQUIPNAME = arr[1]
						_self.planList[i].PK_EQUIP = arr[2]
					}else{
						this.$utils.tips('非设备二维码,无法使用')
					}
				})
			},
			
			submit() {

				// if (this.outTypeIndex < 2 && _self.mainOrder.PK_PRODUCT == '') {
				// 	return this.$utils.tips(`请选择所属产品`)
				// } else if (this.outTypeIndex == 3) {
				// 	if (_self.mainOrder.PK_ZJGC == '') {
				// 		return this.$utils.tips(`请选择在建工程`)
				// 	} else if (_self.mainOrder.PK_YFGC == '') {
				// 		return this.$utils.tips(`请选择研发工程`)
				// 	} else if (_self.mainOrder.PK_DCHS == '') {
				// 		return this.$utils.tips(`请选择单车核算项目`)
				// 	} else if (_self.mainOrder.PK_HSFL == '') {
				// 		return this.$utils.tips(`请选择费用分类核算`)
				// 	}
				// }

				// if (this.outTypeIndex != 2 && _self.mainOrder.YWLXNAME == '') {
				// 	return this.$utils.tips(`请选择业务类型`)
				// }

				let data = {
					"FRBILLNO": _self.mainOrder.BILLNO,
					"BILLFROM": BILLFROM,
					"PK_SUPPLY": _self.mainOrder.PK_SUPPLY, // 供应商编号
					"PK_STORE": _self.mainOrder.PK_STORE, //CKGL20190802000001
					"STORENAME": _self.mainOrder.STORENAME, // 测试仓库
					"VMEMO": VMEMO,
					"userId": _self.userInfo.USERID,
					"account": _self.userInfo.ACCOUNT,
					"Detail": JSON.stringify(_self.planList),
					..._self.mainOrder
				}
				console.log(_self.planList)

				for (var i = 0; i < _self.planList.length; i++) {
					let item = _self.planList[i];
					if (!item.ISSURE) {
						let myIndex = i + 1;
						this.$utils.tips('第' + myIndex + '个物资未进行扫码确认，请先扫物资二维码进行确认');
						return;
					} else if (item.STORENAME_TJ != item.STORENAME && !item.VMEMO) {
						this.$utils.tips('第' + myIndex + '个物资未使用推荐货位，请在备注中说明。');
						return;
					}
				}


				let URL = ajaxUrl;
				this.axios({
					url: URL,
					data: data,
					isLoading: 1
				}).then(res => {
					this.$utils.tips('提交成功！' + res.Message)
					utils.delayBack();
				})
			}
		}
	}
</script>

<style scoped>
	.card-wrapper {
		padding: 26upx;
	}

	.line-height-30 {
		line-height: 24px !important;
	}

	

	.sub-table-input {
		margin-top: 10upx;
	}

	.down-arrow {
		right: 26rpx;
		top: -10rpx;
	}

	.down-arrow-btn {
		top: -20upx;
		right: 0upx;
		font-size: 40upx;
		padding: 10upx;
	}
</style>
